/**
 * 获取老师详情
 * 
 * /admin/teacher/getdetail
 */

const User_info = require('../../../models/usersInfo')
const utils = require('../../../utils/index')
const $ = require('../../../utils/common')

const get_teacher_datail = async function (req, res) {
    try {
        // 根据user_id查询学生信息
        const sql_res = await User_info.findOne({
            where: {
                id: req.query.id,
            },
            attributes: ['user_name', 'user_fullname', 'user_address', 'user_phone', 
             'office_phone', 'user_short_number', 
            'user_email', 'user_qq', 'user_wechat', 
            'user_role', 'user_sex'],
        })

        if (sql_res == null) {
            $.sendMessage(res, 1015, '无效id')
            return
        }

        if (sql_res.dataValues.user_role == 'student') {
            $.sendMessage(res, 1015, '水平越权')
            return
        }
        
        res.json({
            code: 200,
            message: 'success',
            data: sql_res
        })

        // 日志
        utils.create_a_log(req, '教师详情', '浏览')
    }
    catch(error) {
        $.sendMessage(res, 0000, 'error' + error)
        return
    }
}
    
module.exports = get_teacher_datail